<template>
  <el-dialog
    :visible.sync="dialogFormVisible"
    width="80%"
    :append-to-body="true"
    :close-on-click-modal="false"
    center
  >
    <template slot="title">
      <span class="add-main-tital">
        <h4>当前物资明细</h4>
      </span>
    </template>
    <div class="add-container">
      <div class="add-main">
        <div class="table-list">
          <el-table
            v-loading="listLoading"
            :data="ruleForm.rows"
            :element-loading-text="elementLoadingText"
            highlight-current-row
            height="100%"
            :header-cell-style="{
              'border-bottom': '1px solid #cbcccd',
              'border-top': '1px solid #cbcccd',
            }"
            @selection-change="setSelectRows"
          >
            <el-table-column show-overflow-tooltip label="序号" width="50">
              <template #default="scope">
                {{
                  scope.$index +
                  listQuery.pageSize * (listQuery.pageIndex - 1) +
                  1
                }}
              </template>
            </el-table-column>
            <!-- <el-table-column show-overflow-tooltip prop="wuzibm" label="物资代码"></el-table-column> -->
            <el-table-column
              show-overflow-tooltip
              prop="wuzimc"
              label="物资名称"
            ></el-table-column>
            <el-table-column
              show-overflow-tooltip
              prop="biaozhundwsl"
              label="物资数量"
            ></el-table-column>
            <el-table-column
              show-overflow-tooltip
              prop="jiliangdw"
              label="计量单位"
            ></el-table-column>
            <el-table-column
              show-overflow-tooltip
              prop="wuziqfmc"
              label="物资区分"
            ></el-table-column>
            <el-table-column
              show-overflow-tooltip
              prop="huoweimc"
              label="货位"
              width="150"
            ></el-table-column>
          </el-table>
          <el-pagination
            background
            :current-page="listQuery.pageIndex"
            :page-size="listQuery.pageSize"
            :layout="layout"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          ></el-pagination>
        </div>
      </div>
    </div>

    <span slot="footer" class="dialog-footer">
      <el-button
        size="medium"
        type="primary"
        icon="el-icon-s-check"
        @click="save"
      >
        确定
      </el-button>
      <el-button size="medium" icon="el-icon-delete" @click="close">
        取 消
      </el-button>
    </span>
  </el-dialog>
</template>
<script>
  import { queryWuziPage } from '@/api/warehousing'
  import { queryKucunmxList } from '@/api/kucun'
  let _listQuery = {
    pageIndex: 1,
    pageSize: 5,
    wuzimc: '',
  }
  export default {
    name: 'AllMx',
    props: {
      datarow: {
        type: Object,
        default: function () {
          return {}
        },
      },
    },
    data() {
      return {
        listQuery: Object.assign({}, _listQuery),
        show: true,
        listLoading: true,
        layout: 'prev, pager, next',
        total: 0,
        elementLoadingText: '正在加载...',
        selectRows: '',
        ruleForm: {},
        tabheight: 500,
        importShow: false,
        dialogFormVisible: false,
        wuzizyid: '',
      }
    },
    created() {},
    mounted() {
      // this.ruleForm = Object.assign({}, this.datarow)
      // console.log(this.ruleForm);
    },
    methods: {
      setSelectRows(val) {
        this.selectRows = val
      },
      async getData() {
        // this.listQuery.wuzimc = this.datarow.wuzimc
        console.log(this.datarow)
        const wzData = await queryKucunmxList(this.listQuery)
        this.total = wzData.data.total
        this.ruleForm = Object.assign({}, wzData.data)
        this.listLoading = false
      },
      showEdit(row) {
        this.dialogFormVisible = true
      },
      close() {
        //  this.$refs['form'].resetFields()
        //  this.form = this.$options.data().form
        this.dialogFormVisible = false
        this.resetlist()
      },
      save() {
        if (this.selectRows.length == 0) {
          this.$message({
            message: '请先勾选数据',
            type: 'warning',
          })
          return
        }
        this.$emit('fetch-data', this.selectRows)
        this.close()
      },
      goBack() {
        this.$parent.addshow = false
      },
      search() {
        this.getData()
      },
      resetlist() {
        this.listQuery = Object.assign({}, _listQuery)
        this.getData()
      },
      handleSizeChange(val) {
        this.listQuery.pageSize = val
        this.getData()
      },
      handleCurrentChange(val) {
        this.listQuery.pageIndex = val
        this.getData()
      },
    },
  }
</script>
<style lang="scss" scoped>
  .search-group {
    display: flex;
    flex-flow: row wrap;

    .search-gropu-item {
      padding: 10px 20px;
      width: calc((100% - 20px * 8) / 2);
      display: flex;

      label {
        width: 0.8rem;
        white-space: nowrap;
        line-height: 0.32rem;
        margin-right: 0.1rem;
      }

      .el-select {
        width: 100%;
      }
    }

    .search-gropu-item-time {
      width: 500px !important;
      padding: 10px 20px;
      display: flex;

      label {
        white-space: nowrap;
        line-height: 32px;
        margin-right: 10px;
      }
    }

    .search-button {
      margin-left: auto;
      padding: 0.1rem 0.2rem;

      .el-button {
        font-size: 0.14rem !important;
      }
    }
  }

  .add-container {
    width: 100%;
    height: 100%;
    z-index: 1000;
    background-color: #f6f8f9;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    overflow: hidden;

    .add-top {
      ::v-deep .el-page-header__title {
        font-size: 16px !important;
      }
    }

    .add-main {
      flex: 1;
      font-weight: bold;
      display: flex;
      flex-direction: column;
      overflow: auto;

      .add-main-top {
        padding: 0.2rem;
        background: #fff;
        border-radius: 0.05rem;

        .add-main-tital {
          font-size: 0.18rem;
          border-left: 0.1rem solid rgb(121, 189, 255);
          padding-left: 0.1rem;

          p {
            margin: 0;
          }
        }

        .search-gropu-item {
          margin-top: 0.2rem;
          width: 90%;
          display: flex;
          // label {
          //   white-space: nowrap;
          //   line-height: 32px;
          //   margin-right: 10px;
          // }
        }

        .el-select {
          width: 100%;
        }
      }

      .add-main-list {
        flex: 1;
        background: #fff;
        box-sizing: border-box;

        .list-button-group {
          display: flex;
          flex-direction: row;
          padding: 15px;

          .button-item {
            padding: 0px 10px;
          }

          .button-item:first-child,
          &:last-child {
            padding: 0px 10px 0 0;
          }
        }
      }

      .el-button {
        font-size: 0.14rem !important;
      }

      ::v-deep {
        .elx-table--header-wrapper {
          background-color: rgb(233, 243, 255);
        }

        .elx-table {
          font-size: 0.14rem !important;
        }

        .elx-body--column {
          height: 0.48rem !important;
          line-height: 0.24rem;
        }

        .elx-header--column {
          background-image: none !important;
          height: 0.48rem !important;
        }

        .el-date-editor.el-input,
        .el-date-editor.el-input--inner {
          width: 100% !important;
        }

        .el-form-item--small.el-form-item {
          margin-bottom: 0px;
          margin-top: 18px;
        }
      }

      .submit-button {
        margin-top: 20px;
        display: flex;
        justify-content: center;
      }
    }
  }

  ::v-deep {
    .el-dialog--center .el-dialog__body {
      min-height: 25vh;
    }
  }
</style>
